#include <cstdio>
#include <cstring>

int c[ 16 ][ ( 1 << 16 ) + 1 ];

int lowbit( int t )
{
    return t & ( t ^ ( t - 1 ) );
}

void add( int *c, int t )
{
    while ( t <= 65536 )
    {
        c[ t ]++;
        t += lowbit( t );
    }
}

int sum( int *c, int t )
{
    int s = 0;
    while ( t >= 1 )
    {
        s += c[ t ];
        t -= lowbit( t );
    }
    return s;
}

int main( )
{
    int n, i, t, j, tt, d, l, left, right, cas = 1;
    __int64 ans;
    char s[ 2 ];
    while ( scanf("%d", &n) && n != -1 )
    {
        memset( c, 0, sizeof( c ) );
        d = 0;
        ans = 0;
        for ( i = 0; i < n; i++ )
        {
            scanf("%d", &t);
            j = 0;
            tt = 0;
            while ( j < 16 )
            {
                if ( t & 1 )
                    tt |= ( 1 << j );
                add( c[ j++ ], tt + 1 );
                t >>= 1;
            } 
        }
        while ( scanf("%s", s) && s[ 0 ] != 'E' )
        {
            if ( s[ 0 ] == 'Q' )
            {
                scanf("%d", &l);
                left = ( ( ( 1 << l ) + ( 1 << ( l + 1 ) ) - ( d & ( ( 1 << ( l + 1 ) ) - 1 ) ) ) & ( ( ( 1 << ( l + 1 ) ) - 1 ) ) ) + 1;
                right = ( 1 << ( l + 1 ) ) - ( d & ( ( 1 << ( l + 1 ) ) - 1 ) );
            //    printf("%d %d %d %d %d %d\n", left, right, d, ( 1 << ( l + 1 ) ), ( d & ( ( 1 << ( l + 1 ) ) - 1 ) ), ( ( 1 << l ) + ( 1 << ( l + 1 ) ) - ( d & ( ( 1 << ( l + 1 ) ) - 1 ) ) ) & ( ( ( 1 << ( l + 1 ) ) - 1 ) ) );
                if ( left > right )
                {
                    ans += sum( c[ l ], ( 1 << ( l + 1 ) ) ) - sum( c[ l ], left - 1 ) + sum( c[ l ], right );
                }
                else
                {
                    if ( left == 1 )
                        ans += sum( c[ l ], right );
                    else
                        ans += sum( c[ l ], right ) - sum( c[ l ], left - 1 );
                }
            //    printf("%d\n", ans);
            }
            else
            {
                scanf("%d", &t);
                d = ( d + t ) & 65535;
            }
        }
        printf("Case %d: %I64d\n", cas++, ans);
    }
    return 0;
}
